package com.che300.kotlin.extand

import android.content.Context
import android.support.v4.content.ContextCompat
import android.text.Html
import android.text.Spanned

/**
 * @author hsh
 * @time 2017/7/3 003 下午 05:01.
 * @doc
 */

/**
 * Html
 */

fun String.toHtml(): Spanned = Html.fromHtml(this)

fun String.color(color: Int): String = if (this.isNotEmpty()) "<font color=\"#" +
        Integer.toHexString(color) + "\">" + this + "</font>" else ""

fun String.color(colorStr: String): String = if (this.isNotEmpty()) "<font color=\"" +
        colorStr + "\">" + this + "</font>" else ""

fun String.color(context: Context, colorRes: Int): String {
    val string = Integer.toHexString(ContextCompat.getColor(context, colorRes))
    return color("#" + string.substring(string.length - 6, string.length))
}

/**
 * 删除线
 */
fun String.del(): String = "<del>$this</del>"

/**
 * 加粗
 */
fun String.strong(): String = "<strong>$this</strong>"